package com.neo.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class DateUtil {

	public static int differentDaysByMillisecond(Date date1, Date date2) {
		int days = (int) ((date2.getTime() - date1.getTime()) / (1000 * 3600 * 24));
		return days;
	}

	public static void main(String[] args) throws ParseException {
		String dateStr = "2008-1-1";
		String dateStr2 = "2008-1-2";
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");

		Date date2 = format.parse(dateStr2);
		Date date = format.parse(dateStr);

		System.out.println("两个日期的差距：" + differentDaysByMillisecond(date, date2));

	}
	

	public static int  getLoanMent(Integer loan_ment, Date loan_sign_date) {
		if (loan_ment==null || loan_sign_date==null)
			return 0;
		
		Date end = new   Date();//取时间
		Calendar   calendar   =   new   GregorianCalendar(); 
		calendar.setTime(loan_sign_date); 
		calendar.add(calendar.MONTH, loan_ment);
		end = calendar.getTime();
		return DateUtil.differentDaysByMillisecond(loan_sign_date, end);
	}
}
